home *** CD-ROM | disk | FTP | other *** search
- COMMENT - C-Kermit 5A Macro Demonstration File
- ;
- ; Filename:
- ; CKEDEMO.INI: Demonstration macros from "Using C-Kermit"
- ;
- ; Authors:
- ; Frank da Cruz, Christine M. Gianone
- ; Columbia University, New York, NY USA 10027
- ;
- ; Date: 23 November 1992
- ;
- set take error on ; Script programming language required!
- check if
- set take error off
-
- echo Executing \v(cmdfile)...
- echo Defining macros:
-
- define errmsg if def \%1 echo \%1, end 1
-
- COMMENT - COPY macro. Only works for single files.
- ;
- echo { COPY}
- define COPY -
- if > \v(argc) 3 - ; Too many arguments given?
- end 1 \%0: too many arguments,- ; Too many, fail.
- if not def \%1 - ; Was a source file given?
- end 1 copy what?,- ; No.
- if not = \ffiles(\%1) 1 - ; Yes, but is it "wild?"?
- end 1 wildcards not allowed,- ; Sorry, no wildcards.
- if not exist \%1 - ; Does source file exist?
- end 1 file \%1 doesn't exist,- ; No, so it can't be copied.
- if not def \%2 - ; Destination file specified?
- end 1 copy \%1 to what?,- ; No, so it can't be copied to.
- if not = \ffiles(\%2) 0 - ; Does it already exist?
- end 1 file \%2 already exists,- ; Yes, so don't write over it.
- if equal "\v(system)" "UNIX" - ; COPY command for UNIX:
- run cp \%1 \%2,- ; cp source destination
- else if equal "\v(system)" "AOS/VS" - ; For AOS/VS:
- run COPY \%2 \%1,- ; COPY destination source
- else run COPY \%1 \%2,- ; Others: COPY source destination
- if exist \%2 end 0,- ; Check our work and return SUCCESS
- else end 1 COPY failed. ; or FAILURE as appropriate.
-
- COMMENT - SPELLNUM macro.
- ;
- echo { SPELLNUM}
- define spellnum if not def \%1 end,-
- else if not numeric \%1 end 1 { Sorry, not a number},-
- else if > \%1 9 end 1 { Sorry, too hard},-
- else if < \%1 0 end 1 { Sorry, I can't spell negative numbers},-
- else goto \%1,-
- :0,echo zero,end,-
- :1,echo one,end,-
- :2,echo two,end,-
- :3,echo three,end,-
- :4,echo four,end,-
- :5,echo five,end,-
- :6,echo six,end,-
- :7,echo seven,end,-
- :8,echo eight,end,-
- :9,echo nine,end
-
- COMMENT - CALC macro. "Pocket calculator". No arguments.
- ;
- echo { CALC}
- define CALC -
- echo Press Return to exit,- ; Say how to exit.
- def \%1 1,- ; Initial condition for loop
- while def \%1 { - ; Loop until they want to exit
- ask \%1 { expression: },- ; Ask for an expression
- echo \flpad(\feval(\%1),10)- ; Evaluate and print answer
- },-
- echo Back to... ; All done
-
- echo { ADDINGMACHINE}
- define ADDINGMACHINE -
- echo Type numbers or press Return to quit...,-
- assign \%3 0,- ; Initialize the sum
- while = 1 1 {- ; Loop till done
- askq \%1,- ; Wait for a number
- if not def \%1 break,- ; Return quits loop
- increment \%3 \%1,- ; Add it to the sum
- write screen \flpad(\%1,10)\flpad(\%3,10),- ; Print number and subtotal
- },-
- echo Total\flpad(\%3,15,.)
-
- COMMENT - ADDEMUP macro, for calling SUM.
- ;
- echo { ADDEMUP}
- def addemup assign \%9 \fexec(sum \%1), -
- if def \%9 echo SUM = \%9, -
- else echo SUM doesn't work for \%1
-
- COMMENT - SUM macro, recursive. Argument:
- ; 1 = limit of sum, a positive number.
- ; Returns sum of 1 through the number.
- ;
- echo { SUM}
- def sum if not def \%1 return,- ; Make sure there is an argument
- if not numeric \%1 return,- ; Make sure argument is numeric
- if not > \%1 0 return,- ; Make sure argument is positive
- if = \%1 1 return 1,- ; If argument is 1, the sum is 1
- else return \feval(\%1 + \fexecute(sum \feval(\%1 - 1)))
-
- COMMENT - SMALLEST macro, recursive. Arguments:
- ; 1 = a number
- ; 2 = a number
- ; 3 = a number
- ; Prints the smallest of the three.
- ;
- echo { SMALLEST}
- def smallest xif < \%1 \%2 {- ; Compare first two arguments
- echo \%1 is less than \%2,- ; The first one is smaller
- xif < \%1 \%3 {- ; Compare it with the third
- echo \%1 is less than \%3,- ; The first one is smaller
- def \%a \%1- ; Copy it to \%a
- } else {- ; The third is smaller
- echo \%1 is not less than \%3,-
- def \%a \%3- ; Copy it to \%a
- }-
- } else {- ; Otherwise
- echo \%1 is not less than \%2,- ; The second is smaller
- xif < \%2 \%3 {- ; Compare it with the third
- echo \%2 is less than \%3,- ; The second is smaller
- def \%a \%2- ; Copy it to \%a
- } else {- ; The third is smaller
- echo \%2 is not less than \%3,-
- def \%a \%3- ; Copy it to \%a
- }-
- }, echo So the smallest is \%a. ; Announce the winner
-
-
- ; (End of CKEDEMO.INI)
-